home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / hardware / rap / rapMap.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  2.4 KB  |  75 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /***************************************************************************
  18.  *    This is a sample code that maps Eisa slot 1 address to the user's
  19.  *    address space. Knowing the Eisa slot 1 base address, the program
  20.  *    maps an ISA card installed there and accesses a register on the
  21.  *    card. 
  22.  ****************************************************************************/
  23.  
  24. #include <stdio.h>
  25. #include <fcntl.h>
  26. #include <errno.h>
  27. #include <sys/types.h> 
  28. #include <sys/mman.h>
  29.  
  30. #define   GPIS    6    /*  offset of GPIS register in our ISA card  */
  31.  
  32. /*
  33.  *    maps RAP-10 card to user's address space
  34.  */
  35. main()
  36. {
  37.  
  38.     caddr_t    eisaAddr;    /*  Eisa slot 1 base address  */
  39.     caddr_t    cardAddr;    /*  our ISA card IO address   */
  40.     off_t      slotOff;     /*  slot 1 Offset (0x1000)    */
  41.     off_t      cardOff;     /*  ISA card offset (0x330 dip-switched) */
  42.     size_t        slotLen;     /*  slot 1 length (0x1000)    */
  43.     int       fd;
  44.  
  45.     slotOff = 0x1000; 
  46.     cardOff = 0x330;
  47.     slotLen = 0x1000; 
  48.  
  49.     /*   open Eisa IO address space  */
  50.     fd = open ("/dev/eisa/eisa0io", O_RDWR );
  51.     if ( fd <= 0 ) {
  52.         printf ("Error accesing Eisa IO, errno = %d\n", errno );
  53.         exit(0);
  54.      }
  55.  
  56.     /*  map Eisa slot 1 address   */ 
  57.     eisaAddr = (caddr_t) mmap ((void *)0, slotLen, (PROT_READ|PROT_WRITE), 
  58.                     MAP_PRIVATE, fd, slotOff);
  59.     if ( eisaAddr < (caddr_t)0 ) {
  60.         printf ("Error mapping, errno = %d\n", errno );
  61.         printf ("eisaAddr = %d [%x]\n", eisaAddr, eisaAddr);
  62.         close(fd);
  63.         exit(0);
  64.     }
  65.  
  66.     printf ("Eisa Adress is: %x\n", eisaAddr );
  67.  
  68.     /*  calculate our ISA card address and print GPIS register  */
  69.     cardAddr = eisaAddr + cardOff;
  70.     printf ("card Address is: %x\n", cardAddr);
  71.     printf ("GPIS register is: %x\n", cardAddr[GPIS] );
  72.     close(fd);
  73. }
  74.     
  75.